home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!mcnc!rutgers!ukma!cwjcc!hal!ncoast!allbery
- From: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
- Newsgroups: comp.sources.misc
- Subject: v04i088: Merged SysV/BSD echo
- Message-ID: <8809200631.AA19899@rocky2>
- Date: 25 Sep 88 01:23:44 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
- Lines: 207
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 4, Issue 88
- Submitted-by: "David MacKenzie" <edf@ROCKY2.ROCKEFELLER.EDU>
- Archive-name: echo
-
- (An *echo program*???) [My sentiments exactly. ++bsa]
-
- After seeing the (system-)vecho command included in the latest "less"
- distribution to address the problem of BSD/AT&T echo incompatibilities,
- I decided that someone might find this useful. As far as I know, it's a
- complete implementation of both the System V and Berkeley echo's. It
- should be especially useful for (non-SunOs) Berkeley users whose echo's
- are the dumber one and aren't built into the shells. It's not derived
- from AT&T code . . . .
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: echo.1 echo.c
- # Wrapped by dave@edfdc on Tue Sep 20 02:27:38 1988
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'echo.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'echo.1'\"
- else
- echo shar: Extracting \"'echo.1'\" \(832 characters\)
- sed "s/^X//" >'echo.1' <<'END_OF_FILE'
- X.TH ECHO 1
- X.SH NAME
- Xecho \- echo arguments
- X.SH SYNOPSIS
- X.B echo
- X[
- X.B \-n
- X] [
- X.B string...
- X]
- X.SH DESCRIPTION
- X.PP
- X.I Echo
- Xdisplays its arguments, separated by single spaces and followed by a
- Xnewline, on the standard output. If no
- X.I string
- Xarguments are given,
- X.I echo
- Xproduces only the newline character.
- XIf the first argument is
- X.IR \-n ,
- Xthe trailing newline is omitted. The
- X.I \-n
- Xis not echoed.
- X.PP
- X.I Echo
- Xrecognizes the following backslash escapes in the
- X.I string
- Xarguments:
- X.TP
- X\e0ooo
- Xoctal ASCII character (ooo are 1-3 octal digits)
- X.TP
- X\eb
- Xbackspace
- X.TP
- X\ec
- Xomit trailing newline; don't print anything more (same as
- X.IR \-n )
- X.TP
- X\ef
- Xform feed
- X.TP
- X\en
- Xnewline (line feed)
- X.TP
- X\er
- Xcarriage return
- X.TP
- X\et
- Xhorizontal tab
- X.TP
- X\ev
- Xvertical tab
- X.TP
- X\e\e
- Xbackslash
- X.SH "SEE ALSO"
- Xcat(1v)
- X.SH AUTHOR
- XDavid MacKenzie (big deal)
- END_OF_FILE
- if test 832 -ne `wc -c <'echo.1'`; then
- echo shar: \"'echo.1'\" unpacked with wrong size!
- fi
- # end of 'echo.1'
- fi
- if test -f 'echo.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'echo.c'\"
- else
- echo shar: Extracting \"'echo.c'\" \(1741 characters\)
- sed "s/^X//" >'echo.c' <<'END_OF_FILE'
- X/* xc
- X% cc -O echo.c -o echo
- X% strip echo
- X */
- X/*
- X * echo - echo arguments
- X * Usage: echo [-n] [string...]
- X *
- X * If the first argument is "-n", the trailing newline is omitted.
- X * The "-n" is not echoed.
- X *
- X * Recognizes System V escape sequences:
- X * \0ooo octal ASCII character (1-3 digits)
- X * \b backspace
- X * \c omit trailing newline; don't print anything more (same as -n)
- X * \f form feed
- X * \n newline (line feed)
- X * \r carriage return
- X * \t horizontal tab
- X * \v vertical tab
- X * \\ backslash
- X *
- X * David MacKenzie
- X * Latest revision: 08/07/88
- X */
- X
- X#include <stdio.h>
- X
- Xmain(argc, argv)
- X int argc;
- X char **argv;
- X{
- X void echo();
- X register int optind;
- X
- X for (optind = 1; optind < argc; ++optind)
- X if (optind != 1 || strcmp(argv[optind], "-n")) {
- X echo(argv[optind]);
- X if (optind < argc - 1)
- X putchar(' ');
- X }
- X if (argc == 1 || strcmp(argv[1], "-n"))
- X putchar('\n');
- X
- X exit(0);
- X}
- X
- Xvoid
- Xecho(s)
- X register char *s;
- X{
- X register int i, /* Digit counter for octal numbers. */
- X n; /* Value of octal numbers. */
- X
- X for (; *s; ++s) {
- X if (*s != '\\')
- X putchar(*s);
- X else
- X switch (*++s) {
- X case 0:
- X putchar('\\');
- X return;
- X case '\\':
- X putchar('\\');
- X break;
- X case '0':
- X for (i = n = 0, ++s; i < 3 && *s >= '0' && *s <= '7'; ++i, ++s)
- X n += *s - '0';
- X --s;
- X putchar(n);
- X break;
- X case 'b':
- X putchar(8);
- X break;
- X case 'c':
- X exit(0);
- X case 'f':
- X putchar(12);
- X break;
- X case 'n':
- X putchar('\n');
- X break;
- X case 'r':
- X putchar('\r');
- X break;
- X case 't':
- X putchar('\t');
- X break;
- X case 'v':
- X putchar(11);
- X break;
- X default:
- X putchar('\\');
- X putchar(*s);
- X break;
- X }
- X }
- X}
- END_OF_FILE
- if test 1741 -ne `wc -c <'echo.c'`; then
- echo shar: \"'echo.c'\" unpacked with wrong size!
- fi
- # end of 'echo.c'
- fi
- echo shar: End of shell archive.
- exit 0
-